Fix java tree..(part 2)
[f432xdd.git] / java / Graph Editor / src / controllers / actions / Rename.java
blob0347b09f91b05012b7375bc98db57228da68828a
1 package controllers.actions;
3 import javax.swing.undo.AbstractUndoableEdit;
4 import models.GraphVertex;
5 import controllers.*;
7 public class Rename extends AbstractUndoableEdit {
8 private static final long serialVersionUID = -7929100929760152271L;
9 private GraphVertex o;
10 private String savedName;
11 private int originalWidth;
12 private SelectionController selectionController;
14 public Rename(String name, SelectionController selectionController)
16 this.selectionController = selectionController;
17 this.savedName = name;
18 this.o = selectionController.getSelectedVertex();
19 originalWidth = o.getWidth();
20 this.redoAction();
23 private void redoAction(){
24 int width = 20 + this.selectionController.getPanel().getDrawTextWidth(savedName);
25 if(width > o.getWidth())
26 o.setWidth(width);
28 String objectName = o.getName();
29 o.setName(savedName);
30 savedName = objectName;
32 public void redo()
34 super.redo();
35 redoAction();
38 public void undo()
40 super.undo();
41 String objectName = o.getName();
42 o.setName(savedName);
43 o.setWidth(originalWidth);
44 savedName = objectName;
46 public boolean isSignificant(){
47 return true;
50 public String getPresentationName(){
51 return "Vertex Hernoemen.";